﻿using System.IO;
using System.Web.Mvc;
using Util.Ui;
using Util.Webs.Mvc;

namespace IterationLife.Extensions.ControllerBase {
    /// <summary>
    /// 权限控制器
    /// </summary>
    //[RoleAuthorize(Ignore = true)]
    [FormExceptionHandler]
    public abstract class PermissionControllerBase : EasyUiControllerBase {
        /// <summary>
        /// 将PartialView输出为字符串
        /// </summary>
        protected string RenderPartialViewToString( Controller controller, string viewName, object model ) {
            var view = ViewEngines.Engines.FindPartialView( controller.ControllerContext, viewName ).View;
            controller.ViewData.Model = model;
            using( var writer = new StringWriter() ) {
                var viewContext = new ViewContext( controller.ControllerContext, view, controller.ViewData, controller.TempData, writer );
                viewContext.View.Render( viewContext, writer );
                return writer.ToString();
            }
        }

        /// <summary>
        /// 客户端返回
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="data">数据</param>
        public ActionResult ClientOk(string message,object data) {
            return Ok( message, Util.Json.ToJson( data ) );
        }

    }
}
